package com.example.spdemo.service;


import com.example.spdemo.entity.User;
import com.example.spdemo.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {
    @Autowired
    private UserMapper userMapper;
    
    public int save(User user){
        if (user.getId() == null){
            return userMapper.insert(user);
        } else {
            return userMapper.update(user);
        }
    }
    
    public List<User> findAll() {
        return userMapper.findAll();
    }
    
    public User findById(Integer id) {
        return userMapper.findById(id);
    }
    
    public int deleteById(Integer id) {
        return userMapper.deleteById(id);
    }
}